package model

import "strings"

const (
	SEP = "/"
)

type Path struct {
	levels []string
}

func NewPath(path string) *Path {
	levels := strings.Split(path, SEP)
	p := &Path{
		levels: make([]string, 0, len(levels)),
	}
	p.add(levels...)
	return p
}

func (this *Path) AddPath(path string) {
	levels := strings.Split(path, SEP)
	this.add(levels...)
}

func (this *Path) add(levels ...string) {
	for _, level := range levels {
		if level == "" {
			continue
		}
		this.levels = append(this.levels, level)
	}
}

func (this *Path) ToString() string {
	return "/" + strings.Join(this.levels, SEP)
}

func (this *Path) GetLastLevel() string {
	if len(this.levels) == 0 {
		return ""
	}
	return this.levels[len(this.levels)-1]
}
